package org.com.yz.dubbo.web.ctrl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringEscapeUtils;
import org.com.yz.common.annotion.Parameter;
import org.com.yz.common.constant.PayConstant;
import org.com.yz.common.util.ClassRefUtil;
import org.com.yz.dal.dao.model.PresentQuery;
import org.com.yz.dal.dao.model.PresentQueryEs;
import org.com.yz.dubbo.api.service.IPresentQueryService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 提现查询接口控制类
 *
 * @ClassName PresentQueryCtr
 * @Author wzc
 * @Date 2018/7/27 9:15
 **/
@RestController
public class PresentQueryCtr {


    @Reference(version = "1.0.0", timeout = 100000, retries = 0)
    private IPresentQueryService presentQueryService;


    /**
     * @param data, sign
     * @Description: 提现查询
     * @author wzc
     * @date 2018/7/27 9:17
     */
    @RequestMapping("/api/presentQuery.htm")
    @Parameter
    public String presentQuery(String data, String sign) {

        PresentQueryEs presentQueryEs = JSONObject.parseObject(StringEscapeUtils.unescapeJava(data), PresentQueryEs.class);
        PresentQueryEs presentQueryEs1 = new PresentQueryEs();
        PresentQuery res = new PresentQuery();
        try {
            if ("0".equals(presentQueryEs.getBizContent().getChannel())) {
                //收付直通车
                res = presentQueryService.presentHandle(presentQueryEs);
            } else if ("1".equals(presentQueryEs.getBizContent().getChannel())) {
                //银企直连
                res = presentQueryService.withdrawPayQuery(presentQueryEs);
            }
            if (null == res) {
                return ClassRefUtil.createRetData(presentQueryEs, presentQueryEs1, PayConstant.RETURN_DEPOSIT_CODE_ERROR, PayConstant.RETURN_DEPOSIT_CODES_ERROR);
            }
            presentQueryEs1.setBizContent(res);    //返回组装后的数据
            return ClassRefUtil.createRetData(presentQueryEs, presentQueryEs1, PayConstant.RETURN_DEPOSIT_SUCESS, PayConstant.RETURN_ALIPAY_VALUE_SUCCESS);
        } catch (Exception e) {
            presentQueryEs1.setBizContent(null);
            return ClassRefUtil.createRetData(presentQueryEs, presentQueryEs1, PayConstant.RETURN_DEPOSIT_CODE_ERROR, PayConstant.RETURN_DEPOSIT_CODES_ERROR);
        }

    }

}
